include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"

class PublisherNode : public rclcpp::Node
{
public:
    PublisherNode(std::string name) : Node(name)
    {
        RCLCPP_INFO(this->get_logger(), "Hello! I am %s", name.c_str());

        cmd_publisher_ = 
            this->create_publisher<std_msgs::msg::String>("command", 10);

        timer_ = this->create_wall_timer(
                std::chrono::milliseconds(500),
                std::bind(
                    &PublisherNode::timer_callback, 
                    this
                )
        );
    }

private:
    rclcpp::Publisher<std_msgs::msg::String>::SharedPtr cmd_publisher_;
    rclcpp::TimerBase::SharedPtr timer_;

    void timer_callback()
    {
        std_msgs::msg::String msg;
        msg.data = "forward";
        cmd_publisher_->publish(msg);
        RCLCPP_INFO(this->get_logger(), "Publish: %s", msg.data.c_str());
    }
};

int main(int argc, char **argv)
{
    rclcpp::init(argc, argv);
    auto node = std::make_shared<PublisherNode>("Publisher_Node");
    rclcpp::spin(node);
    rclcpp::shutdown();
    return 0;
}


